<template>
    <div class="goods-list">
        <div class="goods-item" v-for="item in goodsList" :key="item.id" @click="goDetail(item.id)" >
            <img :src="item.img_url" alt="">
            <h3 class="title">{{item.title}}</h3>
            <div class="price">
                <span class="new">￥{{item.sell_price}}</span>
                <span class="old">￥{{item.market_price}}</span>
                <div class="price-info">
                    <span>热卖中</span>
                    <span>剩{{item.stock_quantity}}件</span>
                </div>
            </div>
        </div>
        <mt-button type="danger" size="large" @click="getMore">加载更多</mt-button>
    </div>
</template>

<script>
    export default {
        name: "GoodsList",
        data(){
            return{
                pageIndex:1,
                goodsList:[]
            }
        },
        created(){
          this.getGoodsList()
        },
        methods:{
            getGoodsList(){
                this.$http.get("api/getgoods/?pageindex="+this.pageIndex).then(result=>{
                    console.log(result.body.message);
                    this.goodsList=this.goodsList.concat(result.body.message)
                })
            },
            getMore(){
                this.pageIndex++;
                this.getGoodsList();
            },
            goDetail(id){
                this.$router.push("/home/goodsinfo/"+id)
            }
        }
    }
</script>

<style scoped>
    .goods-list{
        display: flex;
        flex-wrap: wrap;
        padding: 8px;
        justify-content: space-between;

    }
    .goods-list .goods-item{
        width: 49%;
        border: 1px solid #ccc;
        box-shadow: 0 0 8px #999;
        margin-bottom: 8px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        min-height: 248px;
    }
    .goods-list .goods-item img{
        width: 100%;
        display: flex;

    }
    .goods-list .goods-item .title{
        font-size: 14px;
    }
    .goods-list .goods-item .price{
        background-color: #ccc;
        margin: 2px;
        line-height: 30px;
    }
    .goods-list .goods-item .price .new{
        font-size: 16px;
        color: red;
        margin-right: 10px;
        font-weight: bold;
    }
    .goods-list .goods-item .price .old{
        font-size: 12px;
        text-decoration: line-through;
    }
    .goods-list .goods-item .price .price-info{
        font-size: 12px;
        display: flex;
        justify-content: space-between;
        color: rgba(0, 0,0,0.6);
    }
</style>